#!/bin/bash 

#auther:DT
add_glsz(){
n=1
>sz.txt
echo "现在是第$n 个数组 "
read -p "请输入你想定义这个数组的元素的个数:" s_num

for i in `seq $s_num`
do
	echo "${i}个元素"
	read sz
	echo $sz >>sz.txt
done
	gl=($(cat sz.txt))
	echo ${gl[@]} >>glsz.txt
	echo "现在定义的数组的元素有:"
	echo ${gl[*]}
}
query_glsz(){
while :
do
read -p "请输入数组内元素的名字:" u_name
glsz_nr=$(cat glsz.txt |egrep "$u_name")
if (( `cat glsz.txt|egrep "$u_name"|wc -l` == 1 ))
then
	cx_sz=($(echo $glsz_nr))
	echo ${cx_sz[@]}
	sleep 5
else
	echo "$glsz_nr"
	echo "你输入的内容查找依据不够详细:请重新输入："
fi
done
}

main_menu(){
echo "1.增加数组"
echo "2.查询数组"
read -p "请输入你的选项:" option
case $option in
1)
add_glsz
;;
2)
query_glsz
;;
*)
exit
;;
esac
}

main_menu
